package com.weixin.dao;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.jfinal.plugin.activerecord.Model;

public class Use extends Model<Use>{
	public static final Use me = new Use();
	
	public boolean save(Use user){
		String phone = user.get("phone");
		String sql = "select * from users where phone = '"+phone + "' order by gamenum desc";
		Use users = findFirst(sql);
		boolean isSuccess = false;
		if (users==null) {
			isSuccess =  user.save();
		}else {
			if (users.getInt("gamenum")<= Integer.parseInt(String.valueOf(user.get("gamenum")))) {
				users.set("gamenum", Integer.parseInt(String.valueOf(user.get("gamenum"))));
				users.set("date", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
				users.update();
			}
		}
		return isSuccess;
	}
}
